/*
 *  $Id: Poison.cs 1017 2010-05-12 12:10:18Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: яд
    /// Параметры: значение (сила яда)
    /// В конце хода наносит игроку или существу урон, равный силе яда.
    /// </summary>
    public class Poison: FlagAffect {
        public readonly int Value;

        public Poison(int value) {
            Value = value;
        }

        public override string Id {
            get { return "poison"; }
        }
        public override string NameText {
            get { return Name.GetText(Value); }
        }
        public override ElementType Element {
            get { return ElementType.Darkness; }
        }

        public override string DescriptionText {
            get { return Description.GetText(Value); }
        }

        public override int BaseWeight {
            get { return Value * -30; }
        }

    	public override AffectIcon Icon {
            get { return AffectIcon.Poison; }
        }

        public override Affect Clone() {
            return new Poison(Value);
        }

        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnEndOffencePhase += DoPoison;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnEndOffencePhase -= DoPoison;
        }

        private void DoPoison() {
            if (Owner.HasFlag<Poison>()) Owner.DamageBy(NewDamage(DamageType.Darkness, Value));
        }
    }

    /// <summary>
    /// Нанесение яла
    /// Параметры: сила яда
    /// Существо при ударе наносит своей цели яд указанной силы.
    /// </summary>
    public class PoisonAttack: Affect {
        public readonly int Value;

        public PoisonAttack(int value) {
            Value = value;
        }

        public override string Id {
            get { return "poison.attack"; }
        }
        public override string NameText {
            get { return Name.GetText(Value); }
        }

        public override ElementType Element {
            get { return ElementType.Darkness; }
        }

        public override int BaseWeight {
            get { return Value * 30; }
        }

        // TODO: иконка эффекта
        //public override AffectIcon Icon {
        //    get { return AffectIcon.PoisonAttack; }
        //}

        public override Affect Clone() {
            return new PoisonAttack(Value);
        }
 
        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnHit += DoHit;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnHit -= DoHit;
        }

        private void DoHit(Creature hitter, AbstractObject target, int damage) {
            if (target is Creature) target.AddAffect(new PoisonAttack(Value));
        }
    }
}